#ifndef _PAGE_H_
#define _PAGE_H_

#include "base.h"


struct page{
};

#if 0
struct page_dir_entry{
	uint_8 p:1;
	uint_8 rw:1;
	uint_8 us:1;
	uint_8 pwt:1;
	uint_8 pcd:1;
	uint_8 a:1;
	uint_8 resv:1;
	uint_8 ps:1;

	uint_8 gbl:1;
	uint_8 avail:3;

	uint_8 base_l:4;

	uint_16 base_h;
};

#define PD_ENTRY_SIZE	sizeof(struct page_dir_entry)

struct page_tbl_entry{
	uint_8 p:1;
	uint_8 rw:1;
	uint_8 us:1;
	uint_8 pwt:1;
	uint_8 pcd:1;
	uint_8 a:1;
	uint_8 d:1;
	uint_8 pat:1;

	uint_8 gbl:1;
	uint_8 avail:3;

	uint_8 base_l:4;

	uint_16 base_h;
};

#define PT_ENTRY_SIZE	sizeof(struct page_tbl_entry)
#endif

#define PT_P 		0x00000001
#define PT_R		0x00000000
#define PT_RW		0x00000002
#define PT_S		0x00000000
#define PT_U		0x00000004
#define PT_PWB		0x00000000
#define PT_PWT		0x00000008
#define PT_PCD		0x00000000
#define PT_S		0x00000000

#define PG_P 		0x00000001
#define PG_R		0x00000000
#define PG_RW		0x00000002
#define PG_S		0x00000000
#define PG_U		0x00000004
#define PG_PWB		0x00000000
#define PG_PWT		0x00000008
#define PG_PCD		0x00000000
#define PG_S		0x00000000

struct mm_frame{
	uint_32 start_vm;
	uint_32 start_phy;
};


#define KMAP_MSG_SRC		0
#define KMAP_MSG_DST		1
#define KMAP_PD				2
#define KMAP_PT				3


#define PAGE_BLOCK		(64 * 4 * 1024)

#define PD_TOKEN			0xFFC00000		/* get index in page directory */
#define PT_TOKEN			0x003FF000		/* get index in page table */
#define PF_TOKEN			0x00000FFF		/* get index in page frame */

/* page directory index */
#define PD_INDEX(index,vm)		((index) = (((vm) & PD_TOKEN) >> 22))
/* page table index */
#define PT_INDEX(index,vm)		((index) = (((vm) & PT_TOKEN) >> 12))
/* page frame index */
#define PF_INDEX(index,vm)		((index) = ((vm) & PF_TOKEN))

EXTERN uint_32 kmap[1024];


int phy2vm(struct mm_frame *mm,uint_32 *phy, uint_32 *vm);
int vm2phy(struct mm_frame *mm,uint_32 *vm, uint_32 *phy);
int phycopy(uint_32 phy_dst, uint_32 phy_src, uint_32 len);
int vmcopy(uint_32 vm_dst, uint_32 vm_src, uint_32 len);
int kremap(int map_index, uint_32 phy);
int page_info_init(uint_32 phy_size);
int page_alloc(uint_32 *phy_start);
int page_dir_map(uint_32 kmap_vm_pg_dir,uint_32 index,uint_32 phy);
int page_tbl_map(uint_32 kmap_vm_pt_dir,uint_32 index,uint_32 phy);
int page_map(struct mm_frame *mm);
int page_copy(uint_32 pg_phy_dst,uint_32 pg_phy_src);
int page_free(void);
int page_sched(void);

#endif

/* EOF */
